<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    <div class="container-div">
    
    	<div class="col-sm-12 search-collapse">
			<form id="user-form" autocomplete="off">
				<div class="select-list">
					<ul>
						<li>
							表名：
							<input type="text" id="name" name="name">
						</li>
						<li>
							表注释：<input type="text" name="comments"/>
						</li>
						<li class="select-time">
							<label>创建时间： </label>
							<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
							<span>-</span>
							<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
						    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
					</ul>
				</div>
			</form>
		</div>
		
		<div class="btn-group-sm hidden-xs" id="toolbar" role="group">
			<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="project:bizTable:add">
				<i class="fa fa-plus"></i> 添加
			</a>
			<a class="btn btn-success" onclick="importFromDb()" shiro:hasPermission="project:bizTable:add">
				<i class="fa fa-folder-open"></i>数据库导入
			</a>
			<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="project:bizTable:edit">
	            <i class="fa fa-edit"></i> 修改
	        </a>
			<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="project:bizTable:remove">
				<i class="fa fa-remove"></i> 删除
			</a>
		</div>
			
		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table" data-mobile-responsive="true"></table>
		</div>
    </div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('project:bizTable:edit')}]];
        var removeFlag = [[${@permission.hasPermi('project:bizTable:remove')}]];
        var prefix = ctx + "project/bizTable";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "业务生成",
                columns: [{
		            checkbox: true
		        },
				{
					field : 'name', 
					title : '表名' 
				},
				{
					field : 'genType', 
					title : '生成策略' ,
					visible : false
				},
				{
					field : 'parentName', 
					title : '父表名称'  ,
					visible : false
				},
				{
					field : 'comments', 
					title : '表注释' 
				},
				{
					field : 'entityName', 
					title : '实体名称' 
				},
				{
					field : 'packageName', 
					title : '生成包名' 
				},
				{
					field : 'author', 
					title : '作者' 
				},
				{
					field : 'idCata', 
					title : '主键类型' ,
					 formatter: function(value, row, index) {
						 var text = '自增' ;
						 if(value == 2) {
							 text = '字符串'
						 }
						 return text ;
					 }
				},
				{
					field : 'creator', 
					title : '创建人' ,
					visible:false
				},
				{
					field : 'createTime', 
					title : '创建时间' 
				},
				{
					field : 'isImport', 
					title : '支持导入导出'  ,
					 formatter: function(value, row, index) {
						 var text = '否' ;
						 if(value == '1') {
							 text = '是'
						 }
						 return text ;
					 }
				},
				{
					field : 'stateName', 
					title : '状态' 
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="editBzTab(\'' + row.name + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		            	if(row.state != 2) {
		            		actions.push('<a class="btn btn-primary btn-xs  " href="#" onclick="syncBizTab(\'' + row.name + '\')"><i class="fa fa-refresh"></i>同步</a> ');
		            	} else {
		            		actions.push('<a class="btn btn-primary btn-xs " href="#" onclick="genCode(\'' + row.name + '\')"><i class="fa fa-bug"></i>生成代码</a>');
		            	}
		            	
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.name + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
        
        function editBzTab(id) {
        	var url = prefix + "/edit/"+id ;
			createMenuItem(url, "业务表管理");
        }
        

        
        function syncBizTab(name) {
        	$.modal.confirm("确定同步表结构吗？", function() {
        		$.modal.loading("正在处理中，请稍后...");
        		var url = prefix + '/create?name='+name ;
            	var config = {
        	        url: url,
        	        type: 'post',
        	        dataType: 'json',
        	        data: {},
        	        success: function(result) {
        	        	$.modal.msgSuccess('同步成功...........');
        	        	$.modal.closeLoading() ;
        	        	$.modal.refreshTab() ;
        	        }
        	    };
        	    $.ajax(config)
        	})
        }
        
        function genCode(name) {
        	$.modal.confirm("确定要生成" + name + "表代码吗？", function() {
		        location.href = prefix + "/genCode/" + name;
		        layer.msg('执行成功,正在生成代码请稍后…', { icon: 1 });
		    })
        }
        
        function importFromDb() {
        	layer.open({
        		type: 2,
        		area: ['400px',  '400px'],
        		fix: false,
        		//不固定
        		maxmin: true,
        		shade: 0.3,
        		title: '导入接口',
        		content: '/tool/gen/genDialog',
        		btn: ['确定','关闭'],
        	    // 弹层外区域关闭
        		shadeClose: true,
        		yes: function(index, layero) {
        			var windowLayer = window[layero.find('iframe')[0]['name']];
                	var tableName = windowLayer.select_tableName();
                	if(tableName != '') {
                		$.modal.confirm("确定要同步" + tableName + "表至业务表吗？", function() {
            	        	layer.close(index);
            		        var url = ctx + "tool/gen/sync?name=" + tableName;
            		        $.modal.loading("正在处理中，请稍后...");
                        	var config = {
                    	        url: url,
                    	        type: 'get',
                    	        dataType: 'json',
                    	        data: {},
                    	        success: function(result) {
                    	        	$.modal.msgSuccess('同步成功...........');
                    	        	$.modal.closeLoading() ;
                    	        	
                    	        	$.modal.refreshTab() ;
                    	        }
                    	    };
                    	    $.ajax(config) ;
            		    })
                	} 
        	    },
        	    cancel: function(index) {
        	        return true;
        	    }
        	});
        }
       
        
    </script>
</body>
</html>